<template>
	<view class="ffffff" style="padding-bottom: 140rpx;">
		<view class="linerhead">
			<u-navbar leftIcon="" placeholder bgColor="rgba(0,0,0,0)">
			</u-navbar>
			<view class="flexbetween" style="padding: 0 30rpx;" v-if="returnRole(24)">
				<view class="titletext bold hei_text" style="font-size: 40rpx;">自動接單</view>
				<u-switch inactiveColor="rgb(230, 230, 230)" v-model="jdvalue" activeColor="#ffb800"
					@change="changejd(jdvalue)"></u-switch>
			</view>
			<view class="flexbetween margin_top" style="padding: 0 30rpx;" v-if="returnRole(25)">
				<view class="titletext bold hei_text" style="font-size: 40rpx;" v-if="value==true">營業中</view>
				<view class="titletext bold hei_text" style="font-size: 40rpx;" v-else>休息中</view>
				<u-switch inactiveColor="rgb(230, 230, 230)" v-model="value" activeColor="#ffb800"
					@change="change(value)"></u-switch>
			</view>
			<view class="mainpadding" style="padding-bottom: 0;">
				<view class="operate-tab">
					<view class="tab-ong" style="background: none;">
						<view class="tab-two" style="justify-content: space-between;">
							<view class="two-child" v-for="(item, index) in common3" :key="index"
								@click="jumpurl(item.url,item)">
								<view class="callck" style="background: none;">
									<image :src="item.img" mode="" class="tabtwo-img2"
										style="width: 100rpx;height: 100rpx;"></image>
								</view>
								<view class="titl bold margin_top1" style="font-size: 34rpx;">{{ item.name }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding2">
			<view class="flexbetween mainpadding xia bgc2">
				<view class="flexcolumn">
					<view class="xianum">{{userInfo.day_money?userInfo.day_money:0}}</view>
					<view class="xiatext margin_top2">附近會員數</view>
				</view>
				<view class="line"></view>
				<view class="flexcolumn">
					<view class="xianum">{{userInfo.day_order?userInfo.day_order:0}}</view>
					<view class="xiatext margin_top2">店鋪會員數</view>
				</view>
				<view class="line"></view>
				<view class="flexcolumn">
					<view class="xianum">{{userInfo.count_order?userInfo.count_order:0}}</view>
					<view class="xiatext margin_top2">關注會員數</view>
				</view>
			</view>
		</view>
		<view class="mainpadding2" v-if="userInfo.is_has_welfare==1">
			<view class="mainpadding flexbetween radius" style="background-color: #ed4d2d;" @click="goSystemNotice(3)">
				<view class="flexleft">
					<u-icon name="bell-fill" color="#fff" size="16"></u-icon>
					<view class="xiaobai eshiliu margin_left1">新的分享調查領取信息</view>
				</view>
				<u-icon name="arrow-right" color="#fff" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding2">
			<view class="titletext hei_text bold">快捷入口</view>
		</view>
		<view class="operate-tab">
			<view class="tab-ong">
				<view class="tab-two">
					<view class="two-child" v-for="(item, index) in common" :key="index" v-if="returnRole(item.id)"
						@click="jumpurl(item.url,item)">
						<view class="callck">
							<image :src="item.img" mode="" class="tabtwo-img"></image>
						</view>
						<view class="titl " :class="item.type==1?'hong_text':''">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding">
			<view class="titletext hei_text bold">營銷管理</view>
		</view>
		<view class="operate-tab">
			<view class="tab-ong">
				<view class="tab-two">
					<view class="two-child" v-for="(item, index) in common1" :key="index" v-if="returnRole(item.id)"
						@click="jumpurl(item.url,item)">
						<view class="callck">
							<image :src="item.img" mode="" class="tabtwo-img"></image>
						</view>
						<view class="titl " :class="item.type==1?'hong_text':''">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding">
			<view class="titletext hei_text bold">即將上線</view>
		</view>
		<view class="operate-tab">
			<view class="tab-ong">
				<view class="tab-two">
					<view class="two-child" v-for="(item, index) in common2" :key="index"
						@click="jumpurl(item.url,item)">
						<view class="callck">
							<image :src="item.img" mode="" class="tabtwo-img"></image>
						</view>
						<view class="titl">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="ewmshow" mode="center" @close="ewmshow = false" round="20">
			<view class="" style="padding-bottom: 50rpx;max-width: 700rpx;">
				<image src="../../static/image/system/ewmtop.png" mode="" class="ewmtop"></image>
				<view class="flexcenter" v-if="flag==1">
					<uqrcode ref="uqrcode" canvas-id="qrcode" v-bind:value="qrcodeurl" :options="{ margin: 10}"
						size="250">
					</uqrcode>
				</view>
				<view class="flexcenter" v-if="flag==2">
					<uqrcode ref="uqrcode" canvas-id="qrcode" v-bind:value="qrcodeurl2" :options="{ margin: 10}"
						size="250">
					</uqrcode>
				</view>
				<view class="main_size flexcenter bold hei_text mainpadding" style="font-size: 50rpx;">{{userInfo.name}}
				</view>
				<view class="xiaohuang margin_top main_size flexcenter" style="font-weight: bold;font-size: 50rpx;"
					v-if="flag==1">收款碼</view>
				<view class="xiaolv margin_top main_size flexcenter" style="font-weight: bold;font-size: 50rpx;"
					v-if="flag==2">店家碼</view>
			</view>
		</u-popup>
		<u-modal :show="smShow" title="請使用掃描器掃描" confirmColor="#fbb826" confirmText="關閉" @confirm="smShow=false;">
			<view class="slot-content">
				<view class="mainpadding">
					<view class="flexbetween"
						style="border: 1rpx solid #fbb826; padding: 10rpx 20rpx;border-radius: 10rpx;">
						<input type="text" inputmode="none" placeholder="" class="xiaohei" :auto-focus="true"
							v-model="smCode" @confirm="smFn" confirm-type="search" />
						<view class="" @click="saoma">
							<u-icon name="scan" color="#fbb826" size="22"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</u-modal>
		<tabbar ref="tabbarref" :current="1"></tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				common: [{
						id: 1,
						img: "/static/image/workbench/meijin.png",
						name: "帳戶管理",
						url: '/pages/workbench/zichanmx',

					}, {
						id: 2,
						img: "/static/image/workbench/dianpu.png",
						name: "商店管理",
						url: '/pages/workbench/dianpugl'
					}, {
						id: 3,
						img: "/static/image/workbench/quanbaodd.png",
						name: "核銷記錄",
						url: "/pages/workbench/hexiaojl"
					}, {
						id: 6,
						img: "/static/image/workbench/pinglun.png",
						name: "商品評價",
						url: "/pages/workbench/shangpinpj"
					}, {
						id: 7,
						img: "/static/image/workbench/zichanguanli.png",
						name: "發票管理",
						url: '/pages/workbench/invoice'
					}, {
						id: 8,
						img: "/static/image/workbench/yuangongguanli.png",
						name: "員工管理",
						url: "/pages/workbench/yuangonggl"
					}, {
						id: 9,
						img: "/static/image/workbench/shangpin.png",
						name: "商品管理",
						url: "/pages/workbench/shangpingl"
					}, {
						id: 10,
						img: "/static/image/workbench/youpinjiaju_danxian_zhuozi.png",
						name: "分配管理",
						url: "/pages/workbench/zhuotaigl"
					}, {
						id: 11,
						img: "/static/image/workbench/gongnengdingyi.png",
						name: "功能服務",
						url: "/pages/workbench/gongnengfw"
					}, {
						id: 12,
						img: "/static/image/workbench/kehuguanli.png",
						name: "客戶管理",
						url: "/pages/workbench/kehugl"
					}, {
						id: 13,
						img: "/static/image/workbench/tongji.png",
						name: "商品統計",
						url: "/pages/workbench/shangpintj"
					}, {
						id: 14,
						img: "/static/image/workbench/wuliu.png",
						name: "物流管理",
						url: "/pages/workbench/wuliugl"
					}, {
						id: 15,
						img: "/static/image/workbench/zhifu.png",
						name: "收款管理",
						url: "/pages/workbench/duoyuanzf"
					}, {
						id: 16,
						img: "/static/image/workbench/gongzuotai.png",
						name: "工作站",
						url: "/pages/workbench/gongzuot"
					}, {
						id: 17,
						img: "/static/image/workbench/chanpinfenlei.png",
						name: "產品分類",
						url: "/pages/workbench/fenleigl"
					}, {
						id: 18,
						img: "/static/image/workbench/jisuanfangshi.png",
						name: "計算方式",
						url: "/pages/workbench/jisuanfs"
					}, {
						id: 19,
						img: "/static/image/workbench/dayinjgl.png",
						name: "打印機管理",
						url: "/pages/workbench/dayinjgl"
					}, {
						id: 20,
						img: "/static/image/workbench/fendiangl.png",
						name: "分店管理",
						url: "/pages/workbench/fendiangl"
					}, {
						id: 21,
						img: "/static/image/workbench/fukuan.png",
						name: "分店付款",
						url: "/pages/workbench/fendianfktj",

					}, {
						id: 22,
						img: "/static/image/workbench/quanbaodd.png",
						name: "配送訂單",
						url: "/pages/workbench/peisongdd"
					}, {
						id: 23,
						img: "/static/image/workbench/zichanguanli.png",
						name: "結算單",
						url: '/pages/workbench/jiesuand'
					},
					{
						id: 24,
						img: "/static/image/workbench/chanpinfenlei.png",
						name: "計時套餐",
						url: '/pages/workbench/chidaob'
					},
					{
						id: 25,
						img: "/static/image/workbench/guige.png",
						name: "規格範例",
						url: '/pages/workbench/guigefllb'
					},
					{
						id: 26,
						img: "/static/image/workbench/goumai.png",
						name: "購買範例",
						url: '/pages/workbench/goumaixzfl'
					},
					{
						id: 27,
						img: "/static/image/workbench/chuhuo.png",
						name: "出貨範例",
						url: '/pages/workbench/chuhuoxzfl'
					}, {
						id: 28,
						img: "/static/image/workbench/mianyunquan.png",
						name: "繳費",
						url: "/pages/workbench/jiaofei",

					},
					{
						id: 29,
						img: "/static/image/workbench/kehuguanli.png",
						name: "客戶類型",
						url: "/pages/workbench/kehulxgl"
					},
					{
						id: 30,
						img: "/static/image/workbench/quyugl.png",
						name: "區域管理",
						url: "/pages/workbench/quyugl"
					},
					// {
					// 	id: 31,
					// 	img: "/static/image/workbench/fjgl.png",
					// 	name: "房型管理",
					// 	url: "/pages/workbench/fangxinggl"
					// },
					{
						id: 31,
						img: "/static/image/workbench/youhuiquan.png",
						name: "優惠卡類型",
						url: "/pages/workbench/youhuiklx"
					},
					{
						id: 32,
						img: "/static/image/workbench/youhuiquan.png",
						name: "優惠卡管理",
						url: "/pages/workbench/youhuikgl"
					},
					{
						id: 33,
						img: "/static/image/workbench/jiejiari.png",
						name: "節假日價格",
						url: "/pages/workbench/jiejiarigl"
					}, {
						id: 37,
						img: "/static/image/workbench/share.png",
						name: "分享維護",
						url: "/pages/workbench/fenxiangwh",
					}, {
						id: 38,
						img: "/static/image/workbench/shigong.png",
						name: "施工流程",
						url: "/pages/workbench/shigonglc",
					}, {
						id: 39,
						img: "/static/image/workbench/wuliao.png",
						name: "物料管理",
						url: "/pages/workbench/wuliaogl",
					}, {
						id: 40,
						img: "/static/image/workbench/shigongd.png",
						name: "施工單",
						url: "/pages/workbench/shigongd",
					}, {
						id: 41,
						img: "/static/image/workbench/zhuandang.png",
						name: "轉檔",
						url: "/pages/workbench/zhuandang",
					}, {
						id: 42,
						img: "/static/image/workbench/zhuandang.png",
						name: "分店調查領取",
						url: "/pages/workbench/fendiandclq",
					}

				],
				common1: [{
					id: 4,
					img: "/static/image/workbench/youhuiquan.png",
					name: "優惠券管理",
					url: '/pages/workbench/youhuiqgl'
				}, {
					id: 5,
					img: "/static/image/workbench/mianyun.png",
					name: "免運券管理",
					url: "/pages/workbench/mianyunqgl",

				}, {
					id: 34,
					img: "/static/image/workbench/gongnengdingyi.png",
					name: "分銷比例",
					url: "/pages/workbench/fenxiao"
				}, {
					id: 36,
					img: "/static/image/workbench/goodsactive.png",
					name: "商品活動",
					url: "/pages/workbench/goodsactive/goodsactive"
				}, {
					id: 35,
					img: "/static/image/workbench/mianyunquan.png",
					name: "儲值管理",
					url: "/pages/workbench/chuzhigl",
				}, ],
				common2: [{
						img: "/static/image/workbench/yingtinggl.png",
						name: "影廳管理",
						url: "/pages/workbench/yingtinggl"
					}, {
						img: "/static/image/workbench/changdigl.png",
						name: "場地管理",
						url: "/pages/workbench/changdigl"
					}, {
						img: "/static/image/workbench/guanliansp.png",
						name: "關連商品",
						url: "/pages/workbench/guanliansp"
					}, {
						img: "/static/image/workbench/quanbaogl.png",
						name: "票券管理",
						url: "/pages/workbench/quanbaogl"
					},
					{
						img: "/static/image/workbench/quanbaodd.png",
						name: "票券訂單",
						url: "/pages/workbench/quanbaodd"
					}, {
						img: "/static/image/workbench/hexiao.png",
						name: "核銷2",
						url: "/pages/workbench/hexiao"
					}
				],
				common3: [{
					img: "/static/image/workbench/erweima.png",
					name: "收款",
					url: ""
				}, {
					img: "/static/image/workbench/hexiao.png",
					name: "掃一掃",
					url: "/pages/workbench/scancode"
				}, {
					img: "/static/image/workbench/erweima.png",
					name: "店家碼",
					url: ""
				}, ],
				value: false,
				jdvalue: 1, //自動接單,1關閉,2開啓
				ewmshow: false,
				is_yes: false, //是否營業:0=否,1=是
				qrcodeurl: "", //收款碼
				qrcodeurl2: "", //店家碼
				flag: 1, //1收款碼，2店家碼
				userInfo: {},
				isLoad: false,
				is_shop: false, //is_shop是否为商家  1 不是   2是
				authority: [],
				smShow: false,
				smCode: "",
				hy_type: "", //0買賣,1計時，3住宿露营，5工程，6超商
			}
		},
		onLoad() {
			uni.hideTabBar()
		},
		onShow() {
			this.is_login = this.http.checkIsLogin();
			this.$nextTick(() => {
				this.$refs.tabbarref.init()
			});
			if (this.is_login) {
				this.getewm()
			}
			if (this.is_login) {
				this.getInfo()
			}
		},
		methods: {
			returnRole(val) {
				if (this.hy_type == 0) { //買賣不能看
					if (val == 38 || val == 39 || val == 40 || val == 41) { //施工流程，物料管理，施工單，轉檔
						return false
					}
				}
				if (this.hy_type == 5) { //工程不能看
					if (val == 20 || val == 29 || val == 30) { //分店管理，客戶類型，區域管理
						return false
					}
				}
				if (this.is_shop == 2) {
					return true
				}
				let flag = this.authority.some((item) => {
					return item == val
				})
				return flag
			},
			goSystemNotice(type) { //系統通知
				uni.navigateTo({
					url: "/pages/message/systemNotice?type=" + type
				})
			},
			smFn() {
				this.smShow = false
				// 商家端掃碼邏輯
				// 1.核銷優惠券掃碼
				// 2.訂單小票掃碼
				if (this.smCode.indexOf('xiaopiaosm') !== -1) { //小票掃碼
					let queryString = this.smCode.split('?')[1];
					// 使用URLSearchParams解析
					let params = new URLSearchParams(queryString);
					let dataParam = params.get('data');
					// 解码URI组件并解析JSON
					let jsonData = JSON.parse(decodeURIComponent(dataParam));
					this.http.request("/api/Ordergoods/scanPjCode", 'POST', jsonData).then(res => {
						this.http.toast(res.msg)
						this.smCode = ""
					})
				} else if (this.smCode.indexOf('hexiaoyhq') !== -1) { //核銷優惠券
					uni.navigateTo({
						url: "/pages/workbench/hexiaoyhq?" + this.smCode.split('?')[1]
					})
				} else {
					location.href = this.smCode;
				}
			},
			saoma() {
				uni.navigateTo({
					url: "/pages/workbench/scancode"
				})
			},
			getQueryVariable(variable) {
				var query = this.smCode;
				var rooms = query.split('?');
				for (var i = 0; i < rooms.length; i++) {
					var pair = rooms[i].split('=');
					if (pair[0] == variable) {
						return (pair[1].split('&'))[0]
					}
				}
				//或者拼接&後面的值
				var vars = query.split('&')
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split('=')
					if (pair[0] == variable) {
						return pair[1]
					}
				}
			},
			
			weisx() {
				this.http.toast("即將上線，敬請期待！")
			},
			async getewm() {
				// 收款码
				if (this.isLoad) {
					return false
				}
				let res = await this.http.request("/api/shop/getfukuan", "GET", {})
				this.qrcodeurl = res.data + "?id=" + uni.getStorageSync("user_id") + "&shop_id=" + uni.getStorageSync(
					"shop_id")
				// 店家码
				let resp = await this.http.request("/api/index/getshop_url", "GET", {})
				this.qrcodeurl2 = resp.data + "?id=" + uni.getStorageSync("shop_id") + "&issm=1"
				console.log("收款码", this.qrcodeurl);
				console.log("店家码", this.qrcodeurl2);
				this.isLoad = true
			},
			// 二维碼点击预览图片
			ewmfn() {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {
						console.log(res);
						var i = [res.tempFilePath]; //获取当前页面的轮播图数据
						//uniapp预览轮播图
						uni.previewImage({
							current: 0, //预览图片的下标
							urls: i //预览图片的地址，必須要数组形式，如果不是数组形式就转换成数组形式就可以
						})
					}
				});
			},
			change(status) {
				console.log(status)
				if (status == true) {
					var datas = 1
				} else {
					var datas = 0
				}
				this.http.request("/api/shop/is_yes", 'POST', {
					shop_id: uni.getStorageSync("shop_id"),
					is_yes: datas
				}).then(res => {
					this.http.toast('操作成功')
				})
			},
			changejd(datas) {
				this.http.request("/api/shop/Shopedit", 'POST', {
					shop_id: uni.getStorageSync("shop_id"),
					is_autoorder: datas ? 2 : 1
				}).then(res => {
					this.http.toast('操作成功')
				})
			},
			async getInfo() {
				let res = await this.http.request("/api/shop/Shopdeail", "POST", {
					shop_id: uni.getStorageSync("shop_id"),
				})
				if (res.code == 1) {
					uni.setStorageSync("appkey", res.data.appkey)
					uni.setStorageSync("hy_type", res.data.hy_type)
					uni.setStorageSync("opentable_status", res.data.opentable_status)
					uni.setStorageSync("is_sdkfp", res.data.is_sdkfp)
					uni.setStorageSync("is_call_sdkfp", res.data.is_call_sdkfp)
					uni.setStorageSync("is_pos_sdkfp", res.data.is_pos_sdkfp)
					uni.setStorageSync("houtel_type", res.data.houtel_type)
					this.is_yes = res.data.is_yes
					if (res.data.is_yes == 1) {
						this.value = true
					}
					if (res.data.is_autoorder == 2) {
						this.jdvalue = true
					}
					this.hy_type = res.data.hy_type
					this.is_shop = res.data.is_shop
					this.authority = res.data.shopstaff ? res.data.shopstaff.authority.split(",") : []
					this.userInfo = res.data
				} else if (res.code == 0) {
					this.http.toast(res.msg);
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async submit() {
				let res = await this.http.request("/api/shop/Shopedit", 'POST', {
					shop_id: this.shop_id,
					is_call: this.is_call ? 1 : 0, //是否呼叫订單:0=否,1=是
					is_pre: this.is_pre ? 1 : 0, //是否使用预约:0=否,1=是
					is_scan: this.is_scan ? 1 : 0, //是否掃碼开关:0=否,1=是
				})
				if (res.code == 1) {
					this.http.toast("提交成功")
					setTimeout(() => {
						uni.navigateBack(1)
					}, 500)
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			chakanmx() {
				uni.navigateTo({
					url: "/pages/workbench/chakanmx"
				})
			},
			jumpurl(url, item) {
				if (item.name == "收款") {
					this.ewmshow = true
					this.flag = 1
					return false
				}
				if (item.name == "核銷") {
					this.smShow = true
					return false
				}
				if (item.name == "店家碼") {
					this.ewmshow = true
					this.flag = 2
					return false
				}
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bgc2 {
		background-image: url('@/static/image/system/workbenckbgc2.png');
		background-size: 100% 100%;
		border-radius: 20rpx;
	}

	.hong_text {
		color: #ff0000 !important;
	}

	.ewm {
		margin-top: 50rpx;
		width: 300rpx;
		height: 300rpx;
	}

	.ewmtop {
		width: 700rpx;
		height: 250rpx;
	}

	.linerhead {
		// background: linear-gradient(180deg, #fffaed 0%, #fffefe  100%);
		background-image: url('@/static/image/system/header.png');
		background-size: 100% 100%;
	}

	.bgc2 {
		background-image: url('@/static/image/system/workbenckbgc2.png');
		background-size: 100% 100%;
		border-radius: 20rpx;
	}

	.tixian {
		padding: 10rpx 40rpx;
		background-color: #fff7e2;
		border-radius: 50rpx;
	}

	.xia {
		border: 1rpx solid rgb(255, 255, 255);
		border-radius: 20rpx;
	}

	.xianum {
		font-size: 30rpx;
		font-family: DIN-Bold, DIN;
		font-weight: bold;
		color: #360405;
	}

	.xiatext {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #7A540B;
	}

	.line {
		width: 1rpx;
		background: rgba(255, 255, 255, .3);
		height: 50rpx;
	}

	page {
		background-color: #fff;
	}

	.operate-tab {
		.tab-ong {
			background-color: #fff;
			padding: 0 20rpx 30rpx 20rpx;
			border-radius: 20rpx;

			.tab-one-top {
				display: flex;
				align-items: center;

				.titname {
					font-size: 32rpx;
					font-weight: 550;
				}

				.tab-img {
					width: 45rpx;
					height: 45rpx;
					margin-right: 30rpx;
				}
			}
		}

		.tab-two {
			display: flex;
			flex-wrap: wrap;
			border-radius: 20rpx;

			.two-child {
				width: 25%;
				padding-top: 30rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.callck {
					background-color: #f8faff;
					width: 88rpx;
					height: 88rpx;
					border-radius: 10%;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.titl {
					color: #333;
					font-size: 28rpx;
					line-height: 60rpx;
					width: 150rpx;
					text-align: center;
				}

				.tabtwo-img {
					width: 50rpx;
					height: 50rpx;
				}

				.tabtwo-img2 {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
</style>